<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="text" name="username" id="wuhu"> <span id="msg"></span>
<input type="submit">
<script>
    // 创建对象

    document.getElementById("wuhu").onblur=function () {
        var xhttp;
        if (window.XMLHttpRequest) {
            xhttp = new XMLHttpRequest();
        } else {
// code for IE6, IE5
            xhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }

        var username = this.value;

        // 发送请求
        xhttp.open("GET", "http://localhost:8080/Filter-demo/ajaxTest3?username" + username);
        xhttp.send();

        // 处理响应数据
        xhttp.onreadystatechange = function() {
            if (this.readyState == 4 && this.status == 200) {
                if(this.responseText == 'true'){
                    document.getElementById("msg").innerHTML = "用户名已存在"
                }
            }
        };
    }

</script>

</body>
</html>